import Page
from Page import Yomi
from Base.Base import Base
from selenium.webdriver.common.by import By


class YomiCarWindowPage(Base):
    """
    语音训练车窗调节

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的返回键
        self.window_back_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivBack'))

        # 左侧的返回键
        self.window_home_btn = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format('ivHome'))

        # 车控标题
        self.window_control_title_text = (By.XPATH, Yomi.RESOURCE_ID_Assistant.format("tv_title"))

        # 车控名称
        self.window_control_name_icon = (By.XPATH, Yomi.car_control_window_name_icon.format(""))

        # 车控开关
        self.window_control_switch_btn = (By.XPATH, Yomi.car_control_window_switch_btn.format(""))

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.window_back_btn)

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.window_home_btn)

    def get_control_title(self):
        """
        获取车窗列表标题

        :return:获取元素
        """
        return self.find_element_o(self.window_control_title_text)

    def get_control_name(self, index=1):
        """
        获取车控名称

        :return:获取元素
        """
        self.window_control_name_icon = (By.XPATH, Yomi.car_control_window_name_icon.format(index))
        return self.find_element_o(self.window_control_name_icon)

    def get_control_switch(self, index=1):
        """
        获取车控开关

        :return:获取元素
        """
        self.window_control_switch_btn = (By.XPATH, Yomi.car_control_window_switch_btn.format(index))
        return self.find_element_o(self.window_control_switch_btn)

    def click_control_name(self, index=1):
        """
        点击车控名称

        :return:None
        """
        self.window_control_name_icon = (By.XPATH, Yomi.car_control_name_icon.format(index))
        self.click_element(self.window_control_name_icon)

    def click_control_switch(self, index=1):
        """
        点击车控开关

        :return:None
        """
        self.window_control_switch_btn = (By.XPATH, Yomi.car_control_switch_btn.format(index))
        self.click_element(self.window_control_switch_btn)

    def is_display_yomi_car_window(self):
        """
        查看是否进入车窗页

        :return:
        """
        return self.is_display(self.window_control_title_text)
